import axios from 'axios'
import { Toast } from 'vant';
import Cookies from './auth'

// create an axios instance
const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 50000 // request timeout
})

// request拦截器
service.interceptors.request.use(config => {
  if(!config.unLoading){
    Toast.loading({
      duration:0,
      message:'加载中...'
    })
  }
  // config.headers = {
  //   'from':'EJOnline'
  // }  // ej在线
  // const token = Cookies.get('token')
  // if (token) {
	// 	config.headers['Authorization'] = token 
	// }
  return config
}, error => {
  Promise.reject(error)
})

// 响应拦截
service.interceptors.response.use(config => {
  Toast.clear()
  return config
}, error => {
  Promise.reject(error)
})

export default service
